/**
 *    Copyright (C) 2009 Victor Smirnov <aist11@gmail.com>
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License along
 *    with this program; if not, write to the Free Software Foundation, Inc.,
 *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *    See LICENSE.exceptions in the root folder of this project for possible
 *    exceptions
 *
 */

#ifndef _CUBEFS_CORE_API_METADATA_PAGE_WRAPPER_HPP
#define _CUBEFS_CORE_API_METADATA_PAGE_WRAPPER_HPP

#include <cubefs/api/metadata/metadata.hpp>
#include <cubefs/core/api/reflection/type.hpp>

#define CUBEFS_SOURCE "cubefs/core/api/metadata/page_wrapper.hpp:" CUBEFS_AT

namespace cubefs { namespace api {

template <typename Interface>
class PageImplT: public TypedImplT<Interface> {
	typedef PageImplT<Interface> 				Me;
public:

    virtual IDValue GetId()                     = 0;
    virtual Int GetModelHash()                  = 0;
    virtual Int GetPageTypeHash()               = 0;
    virtual BigInt GetFlags()                   = 0;
    virtual void* Ptr()                         = 0;

    virtual Int Size()                          = 0;
    virtual Int GetByte(Int idx)                = 0;
    virtual void SetByte(Int idx, Int value)    = 0;

    static void Init() {
        AbstractType *type = new AbstractType(TypeNameFactory<Interface>::name(), Typed::MyType());
        type_ = type;

        type->AddOperation(new BasicOperation<IDValue (Me::*)()>(type, "GetId", &Me::GetId));
        type->AddOperation(new BasicOperation<Int     (Me::*)()>(type, "GetModelHash", &Me::GetModelHash));
        type->AddOperation(new BasicOperation<Int     (Me::*)()>(type, "GetPageTypeHash", &Me::GetPageTypeHash));
        type->AddOperation(new BasicOperation<Int     (Me::*)()>(type, "Size", &Me::Size));
        type->AddOperation(new BasicOperation<BigInt  (Me::*)()>(type, "GetFlags", &Me::GetFlags));
        type->AddOperation(new BasicOperation<void*   (Me::*)()>(type, "Ptr", &Me::Ptr));

        type->AddOperation(new BasicOperation<Int 	  (Me::*)(Int)>(type, "GetByte", "idx", &Me::GetByte));
        type->AddOperation(new BasicOperation<void    (Me::*)(Int, Int)>(type, "SetByte", "idx", "value", &Me::SetByte));
    }

    CUBEFS_DECLARE_REFLECTION;
};

template <typename Interface>
Type* PageImplT<Interface>::type_ 					= NULL;

typedef PageImplT<Page> 							PageImpl;

template <>
struct ParameterTypeHelper<Page*> {
    static Page* convert(Typed* value) {
        return static_cast<Page*>(value);
    }
};



}}

#undef CUBEFS_SOURCE
#endif
